1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <windows.h>
#include <wininet.h>
#include <iostream.h>
#include <stdio.h>
#pragma comment(lib, "wininet.lib")
int upload(char *server, char *user, char *pass, char *localF, char *remoteF)
{
HINTERNET hInternet;
HINTERNET hFtpSession;
hInternet = InternetOpen(NULL,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
hFtpSession = InternetConnect(hInternet,server,INTERNET_DEFAULT_FTP_PORT, user,pass,INTERNET_SERVICE_FTP, 0,0 );
if(FtpPutFile(hFtpSession, localF, remoteF, FTP_TRANSFER_TYPE_BINARY, 0))
{
return 0;
} else {
return -1;
}
InternetCloseHandle(hFtpSession);
InternetCloseHandle(hInternet);
}
int main()
{
if(upload("url ftp server ", "username", "password", "C:\\123.jpg","mypic.jpg")) {
cout<<"File %s uploaded\n";
}
else {
cout<<"File %s failed\n";
//FileSubmit();
system("pause");
return 0;
}
}
|