Advertisement
1_2002 Files #111283

ftp file

Copy a file from a LAN to UNIX and vice versa.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#include <afxinet.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>   
// Set: Project/Settings/General to "Use MFC in a Static Library"
int main(int argc, char* argv[])
{
	char strFileType[1];
	char strDirection[1];
	if (argc < 8)
	{
		printf("\nUSAGE: ftpfile [LAN file] [UNIX file] [File Type: A=Ascii, B=Binary]"); 
		printf("\n[Direction: U=Copy to UNIX, L=Copy to LAN] [Server] [User ID] [Password]\n");
		return 0;
		exit(0);
	}

	CInternetSession iSession("ftpfile",1,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
	CFtpConnection* FtpConn = iSession.GetFtpConnection(argv[5],argv[6],argv[7],INTERNET_INVALID_PORT_NUMBER,FALSE);
	
		
	// Check for Connection
	if(!FtpConn)
	{
		printf("\nERROR: Connection Failed. \nCheck the Server, User ID and Password.\n");
		return 0;
		exit(0);
	}
	
	// File Type Operations
	strncpy(strFileType,argv[3],2);
	strFileType[0]=toupper(strFileType[0]);
	if ((strcmp(strFileType, "A") !=0) && (strcmp(strFileType, "B") !=0)) 
	{
		printf("\nERROR: 'A' or 'B' Must be used for File Type.\n");
		FtpConn->Close();
		iSession.Close();
		delete iSession;
		return 0;
		exit(0);
	}

	// File Copy Operations
	strncpy(strDirection,argv[4],2);
	strDirection[0]=toupper(strDirection[0]);
	if ((strcmp(strDirection,"L") !=0) && (strcmp(strDirection,"U") !=0))
	{
		printf("\nERROR: 'L' or 'U' Must be used for Copy Direction.\n");
		FtpConn->Close();
		iSession.Close();
		delete iSession;
		return 0;
		exit(0);
	}
	// Upload to UNIX
	if (strcmp(strDirection, "U")==0)
	{
		if (strcmp(strFileType, "A")==0)
		{
			if (FtpConn->PutFile(argv[1], argv[2], FTP_TRANSFER_TYPE_ASCII, 0))
				printf("\nUpload Successfull\n");
			else
				printf("\nUpload Failed. \nCheck the file to be copied for existance.\nCheck the File Permissions.\n");
		}
		
		if (strcmp(strFileType, "B")==0)
		{
			if (FtpConn->PutFile(argv[1], argv[2], FTP_TRANSFER_TYPE_BINARY, 0))
				printf("\nUpload Successfull\n");
			else
				printf("\nUpload Failed. \nCheck the file to be copied for existance.\nCheck the File Permissions.");
		}
		
	}
	// Download to LAN
	if (strcmp(strDirection, "L")==0)
	{
	
		if (strcmp(strFileType, "A")==0)
		{
			if (FtpConn->GetFile(argv[2], argv[1], FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_ASCII, 0))
				printf("\nDownload Successfull\n");
			else
				printf("\nDownload Failed. \nCheck the file to be copied for existance.\nCheck the File Permissions.");
		}
		
		if (strcmp(strFileType, "B")==0)
		{
			if (FtpConn->GetFile(argv[2], argv[1], FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0))
				printf("\nDownload Successfull\n");
			else
				printf("\nDownload Failed. \nCheck the file to be copied for existance.\nCheck the File Permissions.");
		}
		
	}
	
	// Close and Exit
	FtpConn->Close();
	iSession.Close();
	delete iSession;
	return 0;
	exit(0);
	
}
Original Comments (3)
Recovered from Wayback Machine