How to move a file on remote FTP server to an dire

2019-03-19 04:16发布

How to move a file on remote FTP server to an directory on same FTP server using Net::FTP in ruby script. I know the file name and I have created a directory using ftp.mkdir but apparently there is no method to move file to the created folder.

标签: ruby ftp
3条回答
你好瞎i
2楼-- · 2019-03-19 04:41

There are putbinaryfile and puttextfile instance methods. Is that not enough ? Or if you just want to move in a scope of ftp server, there is rename method.

查看更多
【Aperson】
3楼-- · 2019-03-19 04:52

Try rename command. If it doesn't work, you can try the following command: "SITE mv oldpath newpath" . This tells the server to execute the command on the server. The expected behavior won't work on all servers but only on some, so use SITE command only when you are sure that it will work with the particular server.

查看更多
在下西门庆
4楼-- · 2019-03-19 04:55

Files (& Directories) can be moved using the rename() method of the Net::FTP Class. Example:

ftp = Net::FTP.new("ftp.myserver.com","myusername","mypassword")
ftp.binary = true
ftp.passive = true

path1 = "/original/dir/path/"    # Dir to move
path2 = "/new/path/"             # New path of Dir

ftp.rename(path1, path2)

And that's it! This causes all files to move from one path to another on the same FTP Server.

查看更多
登录 后发表回答