Closed Thread
Results 1 to 10 of 10

Using VB to upload to an FTP

  1. #1
    Registered User
    Join Date
    06-10-2008
    Posts
    4

    Using VB to upload to an FTP

    I'm looking for a way to automatically upload a file to an FTP site. I'm currently writing out a text file, but then have to use an FTP app to move the file over... any thoughts on how to best do this?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello CCK,

    Welcome to the Forum!

    As a new member of the forum, please take a few minutes and read the forum rules for posting and general etiquette. To see them, click on the link below...

    Forum Rules

    There are two ways to use the FTP with VBA. One is to create and run a batch file or to user API calls. Personally, I feel the API is easier and safer to use. Change the information marked in red below to match your information.
    Please Login or Register  to view this content.
    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    06-10-2008
    Posts
    4

    A couple question on your posting

    Leith, thanks that was fast.

    I'll work with this tomorrow, to see if I can get it running properly.
    I did a quick test, and had an error "duplicate definition" on the "Dim hostFile As String"

    any thoughts, I don't see it in another place?

    also, a couple quick questions, is the "hostFile" a new name that will be used to rename the localFile when it's place on the FTP?

    localFile = "C:\My Documents\Test.Txt"
    hostFile = "\\My Test File.txt"

    thanks

    CCK

  4. #4
    Registered User
    Join Date
    06-10-2008
    Posts
    4

    Thumbs up It works great..!

    Ok, I had to try tonight, and it works great...!

    I just commented out the one error, and it's fine..

    I do have another question though... The location I'm trying to put the file is several layer down...

    The FTP site is 123.123.xxxx.xxx

    But when it try to use the following it fails...

    123.123.xxxx.xxx/folder1/folder2/

    how should I input this to make it work properly...

    Thanks for the help... !!

    CCK

  5. #5
    Registered User
    Join Date
    06-10-2008
    Posts
    4

    Re: Using VB to upload to an FTP

    Can you please mark this as solved... !

    thank you

  6. #6
    Registered User
    Join Date
    02-13-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Using VB to upload to an FTP

    Hey Leith, your code is very useful. Is there some statement on copyright, reuse, licence you can give as I want to include it in a project and credit without problems surfacing later.

  7. #7
    Registered User
    Join Date
    11-20-2011
    Location
    Odisha, India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Using VB to upload to an FTP

    Fantastic solution to add file to an FTP site thru excel VBA.

    But one thing more. Can we add a folder it its not exist in the ftp site.

    I mean if there is not a specific folder in the ftp we can create a folder into the ftp site and within that folder we have to put a local file.

    Please sir I shall be glad if you can give the code for it.
    Last edited by Paul; 08-22-2014 at 12:38 PM. Reason: Removed quote of full post

  8. #8
    Registered User
    Join Date
    11-20-2011
    Location
    Odisha, India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Using VB to upload to an FTP

    How can we add a folder to an ftp site

  9. #9
    Registered User
    Join Date
    12-03-2011
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Using VB to upload to an FTP

    Hi Leith,
    The macro works fine, indeed. Thx a lot!
    How could I possibly upload a file to a subdirectory to the root (like "\XML")?
    Thanks in advance for your answer.
    Erik
    Last edited by Paul; 08-22-2014 at 12:38 PM. Reason: Removed quote of full post

  10. #10
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Using VB to upload to an FTP

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1