Solved

FtpPutFile Unable to save the file to the FTP Server

Posted on 2006-07-13
7
863 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
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.
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 …

728 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