Solved

FtpPutFile Unable to save the file to the FTP Server

Posted on 2006-07-13
7
842 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
Comment Utility
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
Comment Utility
"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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:aboskoco
Comment Utility
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
Comment Utility
I think that it should be a string. You have simply misspelt it.
0
 

Author Comment

by:aboskoco
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

772 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

12 Experts available now in Live!

Get 1:1 Help Now