使用 Ruby 在 ftp 站点上移动和重命名文件 [英] Move and Rename file on ftp site with Ruby

查看:46
本文介绍了使用 Ruby 在 ftp 站点上移动和重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 net-sftp gem 将文件下载到内存中:

I am using the net-sftp gem to download a file to memory:

sftp = Net::SFTP.start('ftp.myapp.com','user_name', :password => 'password')

records = sftp.download!("luigi/List.csv")

然后我需要移动位于 luigi/List.csv 的远程文件并重命名它.

I then need to move my file, located remote at luigi/List.csv and rename it.

我想把它移到这里:

"luigi/archive/List_#{Time.now}.csv"

然后我想删除位于 luigi/List.csv 的原始文件.

I would then like to delete the original file, located at luigi/List.csv.

如何使用 ruby​​ 2.0.0 和 rails 4.0.0 移动、重命名和删除我的 FTP 站点上的文件?

How can I use ruby 2.0.0 and rails 4.0.0 to move, rename, and delete a file on my FTP site?

推荐答案

使用rename:

sftp.rename("luigi/List.csv", "luigi/archive/List_#{Time.now}.csv")

假设 luigi/archive 存在.

要删除,有remove 功能.请参阅 Net::SFTP 常见问题解答.

To just delete, there is the remove function. See the Net::SFTP FAQ.

这篇关于使用 Ruby 在 ftp 站点上移动和重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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