-
May 28th, 2014, 06:01 AM
#1
[RESOLVED] Upload to FTP-Server using the wininet-InternetFunctions
Hiho,
I'm using the Internet-Functions of wininet.dll (InternetOpen, FtpPutFile etc.)
Until last week it worked without problems.
Now i got the following Problem:
My Code creates a xml-file locally and saves it to harddisk in a specified folder --> No Problems
The Code takes this file and via the Internet-Functions (see above) it transfers it to a Folder on a FTP-Server --> No problems until this Monday.
This monday i got a call from the guy operating the FTP-server telling me it was an empty file (0 Bytes!)
So it creates the file, but it doesn't transfer the content of the file.
All Internet-Functions in my Code return No Error
Funny thing: If i transfer the file by hand (e.g. using Windows-Explorer) it showes the correct amount of Bytes (6 Bytes)
Parameters:
Code:
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_INVALID_PORT_NUMBER = 0
Private Const INTERNET_SERVICE_FTP = 1
Public Enum eTransferType
FTP_TRANSFER_TYPE_BINARY = &H2
FTP_TRANSFER_TYPE_ASCII = &H1
End Enum
.
.
.
hOpen = InternetOpen("FTP", _
INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, _
vbNullString, 0)
If hOpen Then
hConnection = InternetConnect(hOpen, _
sRemoteHost, INTERNET_INVALID_PORT_NUMBER, _
sUsername, sPassword, INTERNET_SERVICE_FTP, 0, 0)
End If
nTransferMode = FTP_TRANSFER_TYPE_ASCII
bResult = FileUpload(sLocalFile, sRemoteFile, nTransferMode)
Public Function FileUpload( _
ByVal sLocalFilename As String, _
ByVal sRemoteFilename As String, _
Optional ByVal nTransferType As eTransferType = _
FTP_TRANSFER_TYPE_BINARY) As Boolean
FileUpload = FtpPutFile(hConnection, _
sLocalFilename, sRemoteFilename, nTransferType, 0)
End Function
Any idea what might have changed?
I'm sitting behind a proxy, but that was never an issue. Could it have to do with accessing rights on the remote site?
Any help appreciated
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
May 28th, 2014, 06:12 AM
#2
Re: Upload to FTP-Server using the wininet-InternetFunctions
try changing to FTP_TRANSFER_TYPE_BINARY and see if this does change the behaviour. If the code worked before and you have not changed anything then it is unlikely that the ftp uploading code has got anything to do with it. if you are able to upload the file manually from the very same computer then it is unlikely that things like proxy, firewall or access rights are preventing the upload (in addition it is unlikely that there would be a 0 Byte file created).
also try your program uplolading a different xml file preferably one that was successfully uploaded in the past. My assumption would be that there is something wrong with the file you want to upload. for example i could imagine a zero byte in the beginning of the file in combination with FTP_TRANSFER_TYPE_ASCII could result in the upload beeing stoped when the 0 is encountered.
-
May 28th, 2014, 06:32 AM
#3
Re: Upload to FTP-Server using the wininet-InternetFunctions
Good idea with trying an old file, but has the same result.
Empty file with zero bytes.
My xml starts like this
Code:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!DOCTYPE CarloAuftragIn []>
<CarloAuftragIn>
.
.
.
.
I compared all my files in my archive (all successful transfers in the past) with the current file. All files have the same header.
Still have to try the BINARY-approach
EDIT: Nope, same result with Binary transfer. Empty file with zero bytes
Last edited by Zvoni; May 28th, 2014 at 06:35 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
May 28th, 2014, 07:00 AM
#4
Re: Upload to FTP-Server using the wininet-InternetFunctions
hmm ok then my theory does not work out
your problem seems to be known https://www.google.com/search?q=FtpP...zero+byte+file. firewall settings are mentioned although i would have expected the firewall to block everything and no 0 Byte file beeing created. also access rights on the ftp get mentioned (changed on monday?). could also be an update on the client or server that was installed on monday...
as a quick fix you could create a bat file with all required ftp commandline commands and run the bat from your program, not elegant but as you say you can upload manually this should work. maybe FtpPutFile got broke with a recent IE update on your machine?
-
May 28th, 2014, 07:09 AM
#5
Re: Upload to FTP-Server using the wininet-InternetFunctions
Hi Shaman,
First off: thx for taking time to think about my problem.
No updates on my machine for the last 2-3 months, so nothing there.
Yes, the bat is an idea, but i would have to figure out the commandline-parameters first :-) (never worked with it)
Maybe an update on the server? Might be. Still waiting for an answer from the FTP-Operator (The FTP-Server belongs to a freight carrier, which we're using to announce freight for them to collect and transport)
Yes, i also found some entries after using google with nearly the same search-phrase as you
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
May 28th, 2014, 07:49 AM
#6
Re: Upload to FTP-Server using the wininet-InternetFunctions
Funny thing: If i transfer the file by hand (e.g. using Windows-Explorer) it showes the correct amount of Bytes (6 Bytes)
if it works with windows explorer, you could try using a shell object to upload the file
Code:
Set Sh = CreateObject("shell.application")
set ftpdir = sh.namespace("ftp://username:password@ftp.someweb.com.au/somefolder")
ftpdir.copyhere "C:\test\somefile.txt"
change all paths and filenames to suit, supply valid username and password
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 28th, 2014, 09:59 AM
#7
Re: Upload to FTP-Server using the wininet-InternetFunctions
Nice, pete.
didn't think on that. Will try on monday. In germany is holiday tomorrow, and i took off friday, so next i'll be able to test it will be coming monday.
will report on monday if it worked
thanks
zvoni
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
May 28th, 2014, 04:41 PM
#8
Re: Upload to FTP-Server using the wininet-InternetFunctions
i admit to being a fan of shell object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 3rd, 2014, 03:24 AM
#9
Re: Upload to FTP-Server using the wininet-InternetFunctions
Very curious.
I tried pete's suggestion with the Shell-Object, and i got the following phenomenon:
I have a Windows-Explorer open connected to the Folder on the FTP-Server (for watching in realtime)
If i execute the code with the Shell-Object, my XML-File appears in the FTP-Folder with Size 6 KB (CORRECT!!)
If i then refresh the Explorer-Window (F5-Key) or try to access the xml on the Server the size of the file returns back to 0 bytes and an empty file
btw: I have to rectract my earlier statement, that i can copy the file by hand.
Yes, after copying the file by hand it appears with 6KB as size, but after a refresh it returns back to 0 bytes
Any ideas? I'm really stumped with that
I've read somewhere on the net that it can be something with the firewall, because some FTP-Functions try to reconnect back from the Server to you, and it might be that my firewall is blocking this reconnect
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jun 3rd, 2014, 03:56 AM
#10
Re: Upload to FTP-Server using the wininet-InternetFunctions
pfff.. this is more than strange i'd say. have you tried downloading the file from the ftp again to see if it comes back as 0 or 6kb? if it really comes back as 0 bytes and you do not get any error while uploading the file in the first place then my suspicion would be that some process on the server zaps the file?! i'd use filezilla and upload a bigger file to test if the time required to do the upload does make sense, i.e. if all bytes are sent out from your machine, if so then there is most likely something going on on the server...
-
Jun 3rd, 2014, 04:05 AM
#11
Re: Upload to FTP-Server using the wininet-InternetFunctions
Something else:
I just tried to upload the file using the ftp.exe commandline-program
Strange thing:
after entering put c:\temp\myfile.xml (which is 6KB)
200 PORT command successful
150 Starting transfer
125 Data connection already open; transfer starting
FTP: 5493 bytes sent in 0.04 seconds 152.58 KB/s
..... and in the explorer-window i use for monitoring the destination-folder it appears with 0 bytes
?!?!?!
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jun 3rd, 2014, 04:23 AM
#12
Re: Upload to FTP-Server using the wininet-InternetFunctions
Originally Posted by Zvoni
FTP: 5493 bytes sent in 0.04 seconds 152.58 KB/s
it appears that the file is sent complete and successfully. try downloading it as suggested. do you have feedback from the ftp serveradmin that your files actually are 0 bytes on his server? this could just be a display issue: https://www.google.at/search?&q=ftp+list+zero+byte
-
Jun 3rd, 2014, 04:37 AM
#13
Re: Upload to FTP-Server using the wininet-InternetFunctions
ok, i see you mention feedback from the server admin in your opening post you also say there that you were able to upload a 6 byte file by hand. maybe the ftp server quota is full? try uploading a 1byte file to check
-
Jun 3rd, 2014, 04:37 AM
#14
Re: Upload to FTP-Server using the wininet-InternetFunctions
Nope.
Getting the file back is an empty file
I just called the FTP-operator.
They had an update last week on monday (the day my code started to misbehave!), but according to him, the update didn't had to do anything with the FTP-Server,
but he's going to check neverthless. Maybe something else is zapping the file.
EDIT: I misspoke in my first post. the file is 6KB not 6bytes
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Jun 3rd, 2014, 04:46 AM
#15
Re: Upload to FTP-Server using the wininet-InternetFunctions
Originally Posted by Zvoni
They had an update last week on monday (the day my code started to misbehave!), but according to him, the update didn't had to do anything with the FTP-Server,
yeah, thats what these guys always say i'd think now that you even cannot upload the file by other means it seems very likely that they broke something on their end and the problem is not your code nor any of the settings under your control. they need to investigate the server/network settings and once your upload works using filezilla or IE then try your program again and it will also work again.
-
Jun 3rd, 2014, 05:17 AM
#16
Re: Upload to FTP-Server using the wininet-InternetFunctions
try uploading to other servers, i am sure you will find it is only the one you are using, possibly something to do with permissions or anti-virus
hard to debug internet issues
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 3rd, 2014, 05:30 AM
#17
Re: Upload to FTP-Server using the wininet-InternetFunctions
I don't have any access to other FTP-sites.
Could someone of you, who has an FTP-Server, make me an account, and PM me the Login-data?
EDIT: I tried to upload the file via a Web-FTP-Provider (Where you provide the name of the FTP-Server and your Login for that Server), and it works.
Now the 1 Million-Bucks-Question is: What's different there?
EDIT2: Resolved. It was a wrong checkbox in our firewall *GROWL*
Last edited by Zvoni; Jun 10th, 2014 at 07:29 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|