本文发表在 rolia.net 枫下论坛下面FTP GET 的一段 程序,但它只支持NON PASSIVE MODE
// Send the type command to put us into binary mode
StrPrintF(FTPCommand, "TYPE I\r\n");
NetUWriteN(FTPCtlSock, (BytePtr)FTPCommand, StrLen(FTPCommand));
if (FTPGetReply(FTPCtlSock, &reply)) goto Exit;
f (reply >= 400) goto Exit;
// Create a data port to get the results
acceptSock = FTPDataAcceptSocket();
if (acceptSock < 0) return;
// Send the RETR command
StrPrintF(FTPCommand, "RETR %s\r\n", argv[1]);
NetUWriteN(FTPCtlSock, (BytePtr)FTPCommand, StrLen(FTPCommand));
// Get Reply from the RETR command
if (FTPGetReply(FTPCtlSock, &reply)) goto Exit;
if (reply >= 400) goto Exit;
addrLen = sizeof(address);
if ((dataSock = accept (acceptSock, &address, &addrLen)) < 0) goto Exit;
errno = FTPDatabaseRead(0, argv[1], dataSock);
// Get Transer complete message
FTPGetReply(FTPCtlSock, &reply);
Exit:
if (errno) printf("\nError: %s", appErrString(errno));
if (acceptSock >= 0) close(acceptSock);
if (dataSock >= 0) close(dataSock);
如果以PASSIVE MODE 工作,上边的程序该怎么修改.更多精彩文章及讨论,请光临枫下论坛 rolia.net
// Send the type command to put us into binary mode
StrPrintF(FTPCommand, "TYPE I\r\n");
NetUWriteN(FTPCtlSock, (BytePtr)FTPCommand, StrLen(FTPCommand));
if (FTPGetReply(FTPCtlSock, &reply)) goto Exit;
f (reply >= 400) goto Exit;
// Create a data port to get the results
acceptSock = FTPDataAcceptSocket();
if (acceptSock < 0) return;
// Send the RETR command
StrPrintF(FTPCommand, "RETR %s\r\n", argv[1]);
NetUWriteN(FTPCtlSock, (BytePtr)FTPCommand, StrLen(FTPCommand));
// Get Reply from the RETR command
if (FTPGetReply(FTPCtlSock, &reply)) goto Exit;
if (reply >= 400) goto Exit;
addrLen = sizeof(address);
if ((dataSock = accept (acceptSock, &address, &addrLen)) < 0) goto Exit;
errno = FTPDatabaseRead(0, argv[1], dataSock);
// Get Transer complete message
FTPGetReply(FTPCtlSock, &reply);
Exit:
if (errno) printf("\nError: %s", appErrString(errno));
if (acceptSock >= 0) close(acceptSock);
if (dataSock >= 0) close(dataSock);
如果以PASSIVE MODE 工作,上边的程序该怎么修改.更多精彩文章及讨论,请光临枫下论坛 rolia.net