Question : Ruby ftp download

Hello all,

I am looking into creating a small ruby script that will ftp into my remote server and download all the files ending with .tar.gz, after they have been downloaded I then delete them from the remote server.

I have the basic ftp stuff sorted out, e.g login but when I tell ruby to fetch *.tar.gz it fails.

I have attached my code as some help, if anyone can help me get around the problem of how to download all the .tar.gz files that will be brilliant!

Thanks Andrew
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
require 'net/ftp'
require 'rubygems'
require 'logger'
 
#Configuration
log = Logger.new('backups.log')
ftp_server = 'ftp_server'
ftp_user = 'username'
ftp_passwd = 'password'
ftp_acct = 'account'
#end config
 
#setup the ftp
ftp = Net::FTP.new(ftp_server)
#login to the server
log.info "Making attempt to login to ftp server, #{ftp_server}"
  ftp.login(user = ftp_user, passwd = ftp_passwd, acct = ftp_acct)
#try and fetch the current backup
#if we missed a night, just fetch all backups found!
  log.info "Making attempt to fetch current backup"
  ftp.get('*.tar.gz')
#we don't want to loose disk space by keeping on the remote server, so lets delete them!
  log.info "Making attempt to delete backup from server"
  ftp.delete('*.tar.gz')
#end the ftp session
  log.info "Logout of ftp server"
  ftp.close
Open in New Window Select All

Answer : Ruby ftp download

whoops sorry tru this one
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
require 'chilkat'
 
ftp = Chilkat::CkFtp2.new()
 
# Any string unlocks the component for the 1st 30-days.
success = ftp.UnlockComponent("Anything for 30-day trial")
if (success != true)
    print ftp.lastErrorText() + "\n"
    exit
end
 
ftp.put_Hostname("www.example-code.com")
ftp.put_Username("example-code.com")
ftp.put_Password("*myPassword1*")
 
# Connect and login to the FTP server.
success = ftp.Connect()
if (success != true)
    print ftp.lastErrorText() + "\n"
    exit
end
 
# Change to the remote directory where the files are located.
# This step is only necessary if the files are not in the root directory
# of the FTP account.
success = ftp.ChangeRemoteDir("vcpp")
if (success != true)
    print ftp.lastErrorText() + "\n"
    exit
end
 
# Download all files with filenames matching "ftp_*.asp"
# The files are downloaded into c:/temp
numFilesDownloaded = ftp.MGetFiles("ftp_*.asp","c:/temp")
if (numFilesDownloaded < 0)
    print ftp.lastErrorText() + "\n"
    exit
end
 
ftp.Disconnect()
 
print numFilesDownloaded.to_s() + " Files Downloaded!" + "\n";
Open in New Window Select All
Random Solutions  
 
programming4us programming4us