Solved

FtpPutFile Unable to save the file to the FTP Server

Posted on 2006-07-13
7
844 Views
Last Modified: 2008-02-01
I cant get the save to the FTP to work.. any insight?
--------------------------------------------------------------------------

All declorations are good.
There is a lot of other code but I have cut out the main problem area and "x" out the info for security perposes, hope you understand

Sub New_Macro()
    Dim oMasterDoc As Document
    Dim oTempDoc As Document
    Dim oFSO As Object
    Dim sTempFile As String
    Dim sTempPath As String
    Dim hConnection As Long
    Dim hOpen As Long
    Dim lRC As Long
    Dim sFTP1 As String
    Dim sFTP2 As String
    Dim sFTPServer As String
    Dim sFTPDir As String

    'Get reference to master document
Set oMasterDoc = ActiveDocument
sTemplate = Environ("Temp") & "\test" & oMasterDoc
oMasterDoc.Save
oMasterDoc.SaveAs sTemplate


Set oFSO = CreateObject("Scripting.FileSystemObject")
sTempFile = oFSO.GetTempName & ".doc"
Set oFSO = Nothing
sTempPath = Environ("Temp") & "\" & sTempFile
If Dir(sTempPath) <> "" Then
    Kill (sTempPath)
End If


sFTP1 = "x"
sFTP2 = "xx"
sFTPServer = "xxx"
sFTPDir = "xxxx"

hOpen = InternetOpen(works great)
hConnection = InternetConnect(works great)
lRC = FtpSetCurrentDirectory(works great)

 
 'Upload the file - this is where I am having the problem.

lRC = FtpPutFile(hConnection, sTempath, sTempFile, FTP_TRANSFER_TYPE_BINARY, 0)
If lRC = 0 Then
       Err.Raise Err.LastDllError, "FTP", "Unable to save the file to the FTP Server."
End If
       

    InternetCloseHandle hConnection
    InternetCloseHandle hOpen

End Sub
0
Comment
Question by:aboskoco
  • 4
  • 3
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17104919
This is the Word area, so can you help us out by telling us which other libraries you are referencing?

BTW, the variables whose value settings you have set to "x..." don't appear to be used anywhere, so you could have left them out altogether.

Also what symptoms are you getting - VB error message, hang, your error message? If it's your error message, what is the value of Err.LastDllError
0
 

Author Comment

by:aboskoco
ID: 17109163
"wininet.dll" is the only Lib I am referencing.

The "x" variables are used in the: hConnection = InternetConnect
Sorry, for got to cut them out because i didn't include the InternetConnect code... that is working fine so no need to look over that.

The error message is Error: 87 = One of the parameters was invalid.

My assumption is that it is either sTempath or sTempFile.

Thanks
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17113655
Are you using Option Explicit? Probably not, because if you were, you would get a Compile error, telling you that the  variable sTempath is not defined.

You can make the editor add this automatically to new code and form modules at creation time by making sure that the Tools/Options, Edtor tab, Required Variable Declaration checkbox is ticked.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:aboskoco
ID: 17131084
Your correct.  I did have Option Explicit but I took it out.  What should sTempath represent.  I have difined it as a string previously.  What should I do to solve this problem?

thanks
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17136937
I think that it should be a string. You have simply misspelt it.
0
 

Author Comment

by:aboskoco
ID: 17139675
your right.... hahaahhaaahaha...

Now I am not getting the compile error...

cool... I also figured out that the sTempath was not being saved to the temp file

Thanks for the help

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17140022
I'm very pleased about that.
You can make Word VBA automatically put Option Explicit in each new module via Tools/Options, Editor tab. Tick the 'Require Variable Declaration' checkbox.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

911 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

21 Experts available now in Live!

Get 1:1 Help Now