Solved

FTP Put to Subfolder

Posted on 2014-01-19
7
817 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
ID: 39793175
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
ID: 39793177
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
ID: 39793216
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 150 total points
ID: 39793288
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
ID: 39793332
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
ID: 39793403
Thank you both for helping me to solve this. It works perfectly now!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39793647
You're welcome, glad to help.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

815 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

8 Experts available now in Live!

Get 1:1 Help Now