PDA

View Full Version : Connecting & Downloading via FTP



randomhouse
11-15-2008, 04:35 AM
Hi,

I need to connect to an FTP server and download a file from a specified location. I wrote some VBA code which unfortunately does not work. But it generates a script file - which if I copy into ftp .exe, it works.

Your help will be appreciated. Thanks!
Nitin

PS: Here's my code.
Sub Macro1()
fNum = FreeFile()
Open ThisWorkbook.Path & "\FtpComm.txt" For Output As #fNum
Print #1, "open ftp .site .com" '' I've added spaces here coz it doesnt let me post links
Print #1, "usename"
Print #1, "password"
Print #1, "recv triala" ' close connection
Print #1, "bye" ' Quit ftp program
Close #1
Shell "ftp -s:" & ThisWorkbook.Path & "\FtpComm.txt ", vbNormalNoFocus
'Shell "ftp -n -i -g -s:" & file & vFTPServ, vbNormalNoFocus
End Sub

Kenneth Hobs
11-15-2008, 10:38 AM
Welcome to the forum. Please edit your post and add code tags around your code.

A method that is a bit easier can be seen here. http://vbaexpress.com/forum/showthread.php?t=960

GreenTree
11-15-2008, 04:50 PM
Another working FTP example is posted at http://www.vbaexpress.com/forum/showthread.php?t=16836 from about a year ago. The articles referenced in the third post give some insight into what else you can do with what's there. Obviously there is plenty of room to tweak and condense the code; I tried to make it as clear as possible, which doesn't make for compact.

Hope that helps,

G.T.