How to move a file on remote FTP server to an directory on same FTP server using Net::FTP in ruby script

前端 未结 3 1701
甜味超标
甜味超标 2021-02-08 09:55

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 b

3条回答
  •  感情败类
    2021-02-08 10:20

    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.

提交回复
热议问题