예제 #1
0
파일: fUtils.cpp 프로젝트: CyberShadow/FAR
void FTP::GetCurPath(String& buff)
{
	if(ShowHosts)
		buff = HostsPath;
	else if(!FtpGetCurrentDirectory(hConnect,buff))
		buff.Null();
}
예제 #2
0
파일: fUtils.cpp 프로젝트: CyberShadow/FAR
//---------------------------------------------------------------------------------
void FTP::SaveUsedDirNFile(void)
{
	PROC(("SaveUsedDirNFile","was:(%s,%s)",Host.Home,SelectFile.c_str()))
	PanelInfo pi;

	//Save current file to restore
	if(!ShowHosts && hConnect)
	{
		String s;
		FtpGetCurrentDirectory(hConnect,s);
		StrCpy(Host.Home, s.c_str(), ARRAYSIZE(Host.Home));
	}

	//Save current file to restore
	if(FP_Info->Control(this,FCTL_GETPANELINFO,&pi))
	{
		if(pi.ItemsNumber > 0 && pi.CurrentItem < pi.ItemsNumber)
		{
			SelectFile = FTP_FILENAME(&pi.PanelItems[pi.CurrentItem]);
			Log(("SetLastHost: [%s]", SelectFile.c_str()));
		}

		Log(("Saved (%s,%s)",Host.Home,SelectFile.c_str()));
	}
}
예제 #3
0
char *CzHttp::GetFtpCurrentDir( void )
{
    // FTPカレントディレクトリを取得
    //
    DWORD dwSize = INETBUF_MAX;

    if ( mode != CZHTTP_MODE_FTPREADY ) {
        *buf = 0;
        return buf;
    }
    FtpGetCurrentDirectory( hService, buf, &dwSize );
    return buf;
}
예제 #4
0
파일: fUtils.cpp 프로젝트: CyberShadow/FAR
void FTP::GetCurPath(char *buff,int bsz)
{
	if(ShowHosts)
	{
		StrCpy(buff, HostsPath, bsz);
		return;
	}

	String s;

	if(!FtpGetCurrentDirectory(hConnect,s))
	{
		buff[0] = 0;
		return;
	}

	StrCpy(buff, s.c_str(), bsz);
}
예제 #5
0
int PreProc_FtpDownloadFiles( char *downloadURL, char *tempLocation, int deleteFiles )
{

	if ( IsURL( downloadURL ) && !IsStopped() )
	{
		char	*p;
		long	count=0, filenum;
		char	server[128], path[256], name[64], passwd[32];
#if DEF_WINDOWS
		WIN32_FIND_DATA  lpFindFileData;
		HINTERNET hFind, fs;

		char msg[256];

		ExtractUserFromURL(  downloadURL, server, name, passwd, path );
		DateFixFilename( path, 0 );

		OutDebugs( "Doing PreProcess Download %s...", path );

		fs = (void*)FtpServerOpen( server, name, passwd );

		if ( !fs )
		{
			FtpServerOpenError( server );
			return -1;
		}

		if ( fs )
		{
			long flags = INTERNET_FLAG_NO_CACHE_WRITE;
			char newpath[512];

			// *****************************************************************
			// To be more friendly with various FTP servers, we need to break
			// up the filename from the directory that it is contained in.
			// We can then change to the directory prior to fetching the file.
			// The issue here is that some FTP servers can not get a file that
			// has path information in it (ie: /directory1/dir2/file.dat)
			// *****************************************************************
			int iLen;
			for (iLen=mystrlen(path);iLen && path[iLen]!='/';--iLen)
				;
			if (!iLen)	// then there is no '/'
			{
				mystrcpy( newpath, path+1 );
			}
			else
			{
				path[iLen] = NULL;	// Set the '/' to a NULL so we have a path up to the name.
				if (!::FtpSetCurrentDirectory(fs,"/"))	// Set it to root just to be sure.
				{
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
				}

				if (!::FtpSetCurrentDirectory(fs,path))
				{
					// again.
					// we have a problem, however there is no real way to action this.
					// so lets just hope that the fetch will still work.
					path[iLen] = '/';
				}

				mystrcpy( newpath, path+iLen+1 );
			}


			hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
			if ( !hFind ){
				unsigned long len = 512;
				FtpServerClose( fs );

				OutDebugs( "%s Not Found....Trying root level path instead...", newpath );
				fs = (void*)FtpServerOpen( server, name, passwd );
				if ( fs )
				{
					FtpGetCurrentDirectory( fs, newpath, &len );
					strcat( newpath, path );
					hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 );
				} else
					FtpServerOpenError( server );
			}

			if ( hFind )
				OutDebugs( "Ftp File Found %s size = %d", lpFindFileData.cFileName, lpFindFileData.nFileSizeLow );
			else {
				ErrorMsg( "Cannot open ftp file ...\n%s\nBecause %s", newpath, NetworkErr(NULL) );
				FtpServerClose( fs );
				return -1;
			}

			filenum = 0;

			while( hFind && !IsStopped() )
			{
				long ret;
				char ftpfilename[256], localfilename[256];

				if( hFind )
				{
					ftpfilename[0] = 0;
					if ( !strchr( lpFindFileData.cFileName , '/' ) ){
						// only if NEWPATH has a / in it copy it.
						
						if ( strchr( newpath , '/' ) ){
							mystrcpy( ftpfilename, newpath );
							p = strrchr( ftpfilename, '/');
							if ( p ) *p = 0;
						}
						strcat( ftpfilename, "/" );
						strcat( ftpfilename, lpFindFileData.cFileName );
					} else
						mystrcpy( ftpfilename, lpFindFileData.cFileName );

					// Figure out local file name
					if ( *tempLocation == 0 || GetFileAttributes( tempLocation ) != FILE_ATTRIBUTE_DIRECTORY )
					{
						sprintf( msg, "%%TEMP%%\\%s", FileFromPath( ftpfilename,NULL ) );
						ExpandEnvironmentStrings( msg, localfilename, 255 );
						StatusSetID(  IDS_STOREFILEINTEMP  );
						OutDebugs( "Using system temp location %s", localfilename );
					} else {
						PathFromFullPath( tempLocation, localfilename );
						if( strlen( localfilename ) )
						{
							strcat ( localfilename, "\\" );
							p = FileFromPath( ftpfilename,NULL );
							if ( !p ) p = "temp.log";
							strcat ( localfilename, p );
						} else
							mystrcpy( localfilename, "temp.log" );
						OutDebugs( "Using user temp location %s", localfilename );
					}

					OutDebugs( "Trying to download %d byte file '%s' into '%s' ...", lpFindFileData.nFileSizeLow, ftpfilename, localfilename );

					ret = FtpFileDownload( fs, downloadURL, localfilename, ftpfilename, lpFindFileData.nFileSizeLow );
					if ( ret > 0 )
					{
						if ( deleteFiles ){			// delete remote ftp file after downloading
							StatusSetID( IDS_DELETEFTP, ftpfilename );
							FtpDelFile( fs, ftpfilename );
						}
						AddFileToLogQ( localfilename, filenum++ );
					} else {
						OutDebugs( "error downloading (%d)", ret );
						ErrorMsg( "Cannot download file %s\n%s", NetworkErr(NULL) );
						hFind = NULL;
						FtpServerClose( fs );
						return -2;
					}
					//------------------------
				} //if( hFind )

				if ( hFind ) {
					if( InternetFindNextFile( hFind, &lpFindFileData ) == FALSE )
						hFind = NULL;
				}
			} //while
			FtpServerClose( fs );
		} 
#endif
	}
	return IsStopped();
}