Question

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")

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

I want to move it here:

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

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

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

Was it helpful?

Solution

Use rename:

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

assuming luigi/archive exists.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top