Import an FTP file into Excel

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have an excel workbook and need to import a file for eg East Vat Account.xlsx residing on an FTP site.

I would like VBA code that will enble me to dump the FTP file East Vat Account.xls into a directory called downloads and then to import the file or alternatively to import the file directory from the FTP site

Your assistance will be most appreciated

Regards

Howard
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Create and customise C:\FTP_commands.txt containing:

open your.ftpserver.com
user yourUsername yourPassword
lcd C:\Downloads
cd yourRemoteFolder
binary
get "East Vat Account.xlsx"
bye

Run it using:
Code:
Public Sub Ftp_Download_File()

    Dim FTPcommand As String
    Dim wsh As Object
    
    FTPcommand = "ftp -n -s:" & Chr(34) & "C:\FTP_commands.txt" & Chr(34)
    Set wsh = CreateObject("WScript.Shell")
    wsh.Run FTPcommand, 5, True
    
    Workbooks.Open "C:\Downloads\East Vat Account.xlsx"
    
End Sub
 
Upvote 0
Hi John

Thanks for the help. The macro runs without any glitches, but the workbook "East Vat account" is not downloaded

The script which is saved in notepad on my desktop is "ftp.txt" and is follows:

open 18.2.14.196 (fictitious FTP)
dave (fictitious)
pass (fictitious)
bin
hash
lcd c:\downloads
cd east
mget East Vat*.xls
quit

When I run the sccript in executable mode the workbook is downloaded. However, when I run the macro, it is not downloaded

Your assistance in resolving this matter will be most appreciated
 
Upvote 0
What do you mean by executable mode?

Delete the quit so that the command window stays open and see if there are any errors from the other commands. Also comment out the Workbooks.Open line while testing.
 
Upvote 0
Hi John

The problem seems to be occuring at the user name and passwords as the message comes up invalid login

open 18.2.14.196 (fictitious FTP)
dave (fictitious)
pass (fictitious)
bin
hash
lcd c:\downloads
cd east
mget East Vat*.xls
quit

should it be as follows:

open 18.2.14.196 (fictitious FTP)
user dave (fictitious)
password pass (fictitious)
bin
hash
lcd c:\downloads
cd east
mget East Vat*.xls
quit


Please advise how user name annd password must be set out

Thanks

Howard
 
Upvote 0
"should it be as follows:"

I don't know. Have you tried it?

Did you try the syntax in my OP?

user yourUsername yourPassword
user dave pass

If no joy, type ftp at the command prompt and then help, or help user. Your ftp might be different.
 
Upvote 0
Hi John

Thanks for the reply. I will be out of town for a few days, but will test code when I get back to the office on Friday & will let you know

Thanks

Howard
 
Upvote 0

Forum statistics

Threads
1,214,376
Messages
6,119,179
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top