在Ruby中使用Net :: FTP将整个目录及其内容移动到同一服务器上的另一个位置 [英] Move entire directory and its contents to another location on the same server using Net::FTP in Ruby

查看:95
本文介绍了在Ruby中使用Net :: FTP将整个目录及其内容移动到同一服务器上的另一个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,我想将FTP服务器上的目录移动到同一台服务器上的其他路径。我想用 Net :: FTP 完成这个工作,但也欢迎其他解决方案。



由于没有适当的方法用于在 Net ::中移动文件或目录FTP文档,一个涉及将目录复制到另一个路径并删除原文的解决方案将是更可取的。



请继续关注主题并留下与问题相关的解决方案。

解决方案

好的,我找到了解决方案,而且非常简单。可以使用 Net :: FTP Class的 rename()方法移动文件(&目录)。例子:

  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服务器上从一个路径移动到另一个路径。


As stated in the title, I would like to move a directory on a FTP Server to some other path on the same server. I want to accomplish this using Net::FTP but other solutions are also welcome.

Since there's no proper method for moving files or directories in Net::FTP Documentation, a solution involving copying the directory to another path and deleting the original would be preferable.

Please stay on topic and leave solutions related to the question.

解决方案

Well, I found the solution and it's quite simple. 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将整个目录及其内容移动到同一服务器上的另一个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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