如何使用ruby脚本中的Net :: FTP将远程FTP服务器上的文件移动到同一FTP服务器上的目录 [英] How to move a file on remote FTP server to an directory on same FTP server using Net::FTP in ruby script

查看:118
本文介绍了如何使用ruby脚本中的Net :: FTP将远程FTP服务器上的文件移动到同一FTP服务器上的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ruby脚本中的Net :: FTP将远程FTP服务器上的文件移动到同一FTP服务器上的目录。
我知道文件名,我已经使用ftp.mkdir创建了一个目录,但显然没有办法将文件移动到创建的文件夹中。

方案

使用 Net :: FTP 的 rename()方法可以移动文件code> Class。例子:

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

path1 =/ original / dir / path /#Dir移动
path2 =/新路径/#新路径Dir

ftp.rename(path1,path2)

就是这样!这会导致所有文件在同一个FTP服务器上从一个路径移动到另一个路径。


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.

解决方案

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.

这篇关于如何使用ruby脚本中的Net :: FTP将远程FTP服务器上的文件移动到同一FTP服务器上的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆