Solved

FTP Put to Subfolder

Posted on 2014-01-19
7
757 Views
Last Modified: 2014-01-20
I am trying to use VBA code to upload a file to a SUBFOLDER on a FTP Server. I am successful when I upload directly to the ROOT of the FTP site. When I try to upload to the Subfolder, I get the message "unknown host."

My code looks like this:

    strFTPServ = "ftp://destination.com/uploads"
    strGet = "c:\SourceFolder\" & strFile
    'Mounting file command for ftp.exe
    lngNum = FreeFile()
    Open PATHLOCAL & "\FtpComm.txt" For Output As #lngNum
    Print #1, "user myuser mypassword" 
    Print #1, "bin" 
    Print #1, "put " & strGet ' Send File
    Print #1, "close" ' close connection
    Print #1, "quit" ' Quit ftp program
    Close
    strShell = "ftp -i -n -s:" & PATHLOCAL & "FtpComm.txt " & strFTPServ
    Shell strShell

Open in new window

   

If I remove the /Uploads, the code works PERFECTLY. I am certain that the folder on the FTP server is called Uploads.
0
Comment
Question by:TechMommy
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:Conner Turner
Comment Utility
Hello There,

The FTPserver is not reserved for the destination of the FTP FQDN or IP and serves no purpose to where your file goes, you will need to either name your file with the / Directory and FTP will place it under the named Directory or modify your Script to contain a Directory by Duplicating the Send file or Printing the cd command to another Dir.

HTH,
Conner
0
 
LVL 29

Expert Comment

by:IrogSinta
Comment Utility
The location where you want to put the file should be specified in your text file.

Change lines 1 and 2 to the following:
strFTPServ = "ftp://destination.com"
strGet = "c:\SourceFolder\" & strFile & " /uploads/" & strFile 

Open in new window

0
 
LVL 11

Author Comment

by:TechMommy
Comment Utility
This makes perfect sense, but when I modify the strFTPServ and strGet as suggested by IrogSinta, I no longer receive the error, but the file appears to be placed in the root folder.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
Comment Utility
Basic FTP connections are to the 'root' folder of your account.  To get to any other folder, you must change the current directory with 'cd'.  Many FTP clients will do this for you but if you're writing the code, you have to do it for youself.

http://en.wikipedia.org/wiki/List_of_FTP_commands

Some more examples:  http://www.cs.colostate.edu/helpdocs/ftp.html
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 350 total points
Comment Utility
Looks like Dave is right about the root folder so revise your code to this:
    strFTPServ = "ftp://destination.com"
    strGet = "c:\SourceFolder\" & strFile
    'Mounting file command for ftp.exe
    lngNum = FreeFile()
    Open PATHLOCAL & "\FtpComm.txt" For Output As #lngNum
    Print #1, "user myuser mypassword" 
    Print #1, "bin" 
    Print #1, "cd uploads" 
    Print #1, "put " & strGet ' Send File
    Print #1, "close" ' close connection
    Print #1, "quit" ' Quit ftp program
    Close
    strShell = "ftp -i -n -s:" & PATHLOCAL & "FtpComm.txt " & strFTPServ
    Shell strShell

Open in new window

0
 
LVL 11

Author Closing Comment

by:TechMommy
Comment Utility
Thank you both for helping me to solve this. It works perfectly now!
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome, glad to help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now