News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Write to a file on a FTP

Started by mordred, April 10, 2005, 01:52:08 AM

Previous topic - Next topic

mordred

      Hey everyone, I have this problem: I try to connect to a FTP, create a file there and write something in it. The code I use works fine on a computer(that uses windows 98) but fails on another one(with windows XP). When I say it fails, I mean it creates the file but doesn't write anything in it. What am I doing wrong? I've tried to use FtpPutFile but that didn't work either. Thanks.

SendFileOnFTP proc
        invoke InternetOpen, addr AppName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
        test eax, eax
        jz label_1                            ; Jumps to end of procedure if 'InternetOpen' failed
        mov hInternet, eax
                                                ; We try to open the FTP
        Invoke InternetConnect, hInternet, addr site_name, 21, addr user_name, addr password, INTERNET_SERVICE_FTP, NULL, NULL
        test eax, eax
        jz label_2                       ; Jumps if 'InternetConnect' failed
        mov hFTP, eax                                   

        invoke FtpOpenFile, hFTP, addr file_name, GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY, NULL
        test eax, eax                 
        jz label_3                     ; Jumps if 'FtpOpenFile' failed
                                       
        mov hFile, eax                 
        invoke InternetWriteFile, hFile, addr buffer_to_write, 30, addr nr_of_bytes_written
        invoke InternetCloseHandle, hFile
        label_3:
                invoke InternetCloseHandle, hFTP
        label_2:
                invoke InternetCloseHandle, hInternet
        label_1:
    ret
SendFileOnFTP endp

Brett Kuntz

Erm are you using some sorta socket library? I don't believe any of those functions are winsock functions. Afaik, you can't write to a file over FTP, you can only request to resume uploading to a file from a certain part, which wouldn't be quite the same.

mordred

    I am using 'wininet.lib' from MASM32 lib folder. Still, I don't understand why it works on windows 98 and not on windows XP.

Brett Kuntz

What exactly happens on the XP machine? Does the program crash, error out, or just not connect to the ftp? Is the XP machine behind a router/firewall that might be blocking it?

mordred

      The program doesn't crash, every function seems to work, I've tested them. I might be behind a firewall but I don't understand how I can connect to the same FTP with another application, like Windows Commander, and put, delete or rename files.

mordred

       I've just realized that my program can create an empty file on that FTP with a given name, and, since i just want to send a few bytes, i'll send them as the file's name.  :lol

pbrennick

BTW:  If you watch Windows Commander mannipulating files on the internet you will see that it actually issues *nix commands to the target shell and the shell actually does the work.  Hope that gives you an idea.

Paul

Eóin

Sorry I don't have time to inspect your code, but it may be helpful to you to see some code I had which did the same thing. I hope this bit I'm posting is complete, if not just let me know.

Host, uNme & uPas are just the address, username and password, set elsewhere. MsgBuf & MsgSze are the file contents and size.

proc PutFile,fName
enter
push edi esi ebx
invoke InternetOpen,0,INTERNET_OPEN_TYPE_PRECONFIG,0,0,0
mov [hInt],eax

invoke InternetConnect,[hInt],Host,INTERNET_DEFAULT_FTP_PORT,uNme,uPas,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0
mov [hCnt],eax

cmp eax,0
jne @F

jmp .finish

@@: invoke SendMessage,[gSts],SB_SETTEXT,2,oFle
invoke FtpOpenFile,[hCnt],[fName],GENERIC_WRITE,FTP_TRANSFER_TYPE_BINARY,INTERNET_FLAG_NO_CACHE_WRITE
mov ebx,eax

invoke InternetWriteFile,ebx,MsgBuf,MsgSze,Size

invoke InternetCloseHandle,ebx
invoke InternetCloseHandle,[hCnt]
invoke InternetCloseHandle,[hInt]

.finish:pop ebx esi edi
return


BTW, this is Fasm code but its mostly similar to Masm, for any variable with square brackets "[a]" remove them, and for variables without any stick an "addr" in front  :wink .