怎么获取ftp服务器上指定文件的大小
CFtpConnection连接。
看有的说openfile之后用GetLength或SeekToEnd
我用GetLength返回值总是8192(这个应该是直接返回默认缓冲区大小)
SeekToEnd报错,无效句柄。然后看msdn上说:After calling OpenFile and
until calling Close, the application can only call CInternetFile::Read, CInternetFile::Write, Close, or CFtpFileFind::FindFile.
还有别的方法吗?或者指正下这两种用法的错误。
------最佳解决方案-------------------- 用CFtpFileFind里面有FindFile,然后GetLength就可以了
------其他解决方案-------------------- 这个方法可以获取4G以上的文件大小
if(0!=_fseeki64(m_file.m_pStream,0,SEEK_END))//移到文件末尾
{
m_file.Close();
return 100;
}
m_filesize=_ftelli64(m_file.m_pStream);//获取超大文件大小
_fseeki64(m_file.m_pStream,0,SEEK_SET);//移到文件开头 ------其他解决方案-------------------- 可以用原始指令
size [path]filename
如果文件存在 返回文件长度
否则返回5xx 失败
------其他解决方案-------------------- 有获取文件名字和其他属性的函数,具体查下msdn吧
------其他解决方案-------------------- 没人回答,那我先坐个沙发歇歇。。。
------其他解决方案-------------------- 引用: 有获取文件名字和其他属性的函数,具体查下msdn吧
没找到~帮忙找下吧。谢谢
------其他解决方案-------------------- 引用: 有获取文件名字和其他属性的函数,具体查下msdn吧
没用过原始指令。。代码中怎么实现呢?
------其他解决方案-------------------- 引用: 用CFtpFileFind里面有FindFile,然后GetLength就可以了
FindFile调用成功,GetLength异常。。。
上代码吧。
CInternetSession* pInetSession=NULL;
CFtpConnection* pFtpConn=NULL;
CFtpFileFind* pFtpFFind=NULL;
pInetSession=new CInternetSession(AfxGetAppName(),1,
PRE_CONFIG_INTERNET_ACCESS);
try
{
pFtpConn=pInetSession->GetFtpConnection("101.1.110.136");
pFtpFFind=new CFtpFileFind(pFtpConn);
BOOL b=pFtpFFind->FindFile("@A127K04.mpg");
pFtpFFind->GetLength();
}
catch(CInternetException* pEx)
{
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
AfxMessageBox(szError);
else
{
AfxMessageBox(_T("连接FTP服务器错误,请检查网络连接!"));
}
pEx->Delete();
pFtpConn=NULL;
}
------其他解决方案-------------------- 额。。。对了
filefind.cpp中ASSERT(m_pFoundInfo != NULL && m_pNextInfo != NULL);报错。
增加这个就好:b=pFtpFFind->FindNextFile();
------其他解决方案-------------------- 引用: 用CFtpFileFind里面有FindFile,然后GetLength就可以了
又俩问题:
①不能获取大于4G的文件大小
②vc6下 GetLength64可以用,2005就不能用。。
帮忙解答下。
------其他解决方案-------------------- 查下msdn有没有新函数替代GetLength64和GetLength
------其他解决方案-------------------- 引用: 查下msdn有没有新函数替代GetLength64和GetLength
没发现替代函数。。
vc6的msdn:If the file may be more than four gigabytes in size, use the GetLength64 member.