Solved

FtpPutFile Unable to save the file to the FTP Server

Posted on 2006-07-13
7
867 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
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 shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

628 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