Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FtpPutFile Unable to save the file to the FTP Server

Posted on 2006-07-13
7
Medium Priority
?
881 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 

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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

715 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