Solved

FTP file upload from within Access

Posted on 2016-09-12
1
61 Views
Last Modified: 2016-09-12
I'm working on some code that I copied from Matthew V Carmichael from here.

My current code looks like:
Public Function FTP_SendOneFile(strPath As String, strfilename As String)
'=========================================================================
'FTP from Microsoft Access
'by Matthew V Carmichael
'Creates FTP Batch File, FTP command file (txt)
'Default directory location of files to upload/download is
'the same location as the mdb file that contains this module.
'Modified by Dale Fye on 9/12/2016
'========================================================================='
On Error GoTo Err_Trap

    Dim pFile As Long
    Dim ftpServer As String
    Dim strUserName As String
    Dim strPassword As String
    Dim ftpFolder As String
    Dim dtNow As Date

    If right(strPath, 1) <> "\" then strPath = strPath & "\"
    If Dir(strPath & strfilename) = "" Then
        MsgBox "File not found."
        Exit Function
    End If
    
    If Dir(strPath & "FTP_cmd.txt") <> "" Then Kill strPath & "FTP_cmd.txt"
    If Dir(strPath & "FTP_run.bat") <> "" Then Kill strPath & "FTP_run.bat"
    
    'FTP Server Settings
    ftpServer = "ftpserver"
    ftpFolder = "MyFolder"
    strUserName = "UserName"
    strPassword = "password"
    
    'Create text file containing FTP commands
    pFile = FreeFile
    Open strPath & "FTP_cmd.txt" For Output As pFile
    Print #pFile, "user" & " " & strUserName
    Print #pFile, strPassword
    Print #pFile, "cd " & Chr$(34) & ftpFolder & Chr$(34)
    Print #pFile, "Put " & Chr$(34) & strfilename & Chr$(34)
    'Use the Put command to upload, use the Get command to download.
    'Print #pFile, "Get " & "Your File Name"
    Print #pFile, "Pause"
    Print #pFile, "quit"
    Close pFile
    
    'Create batch file to execute FTP
    pFile = FreeFile
    Open strPath & "FTP_Run.bat" For Output As pFile
    Print #pFile, "ftp -n -s:FTP_cmd.txt" & " " & ftpServer
    Print #pFile, "Pause"
    Close pFile

    'Execute FTP command
    'Shell strPath & "FTP_Run.bat", 1
    
Err_Trap_Exit:
    Exit Function
    
Err_Trap:
    MsgBox Err.Number & " - " & Err.Description
    Resume Err_Trap_Exit

End Function

Open in new window

When I run this function I get an error message: Error opening script file FTP_cmd.txt  
But if I close the command window, select the FTP_Run.Bat file and select Open, the upload runs just fine.  I thought there might be a problem with timing, so I inserted a pause before the shell command, but that makes no difference, I still get the error message

The code in those two files looks like:
FTP_cmd.txt:
user Username
Password
cd "MyFolder"
Put "test file 2016_09_12_1400.txt"
Pause
quit

Open in new window

and FTP_Run.bat
ftp -n -s:FTP_cmd.txt ftpServer
Pause

Open in new window

Any ideas?
0
Comment
Question by:Dale Fye (Access MVP)
1 Comment
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 0 total points
ID: 41795295
The solution was to modify the Put statement to include the path that the file is being uploaded from, then modify the ftp command in the .bat file to include the path where the txt file resides.
0

Featured Post

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iPhone v Android phone 7 34
How to resolve user quota error? 13 34
Access Query based on a Form Field 2 21
Access database form in matrix view 14 16
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

861 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

24 Experts available now in Live!

Get 1:1 Help Now