设想一:是否可以像是对本地生成的文本文档的操作,对其写入自己的IP地址 设想二:在本地上生成一个 IP.TXT 文件,把自己的IP写进去,然后上传到FTP空间
不知道这两种方法那种可行?或是实现起来比较简单还有什么好的方法? 在实现的时候都需要些什么?最好是能给个例程 谢谢 org
不知道这两种方法那种可行?或是实现起来比较简单还有什么好的方法? 在实现的时候都需要些什么?最好是能给个例程 谢谢 org
解决方案 »
- 如何使对话框上的按钮透明既显示对话框的位图或背景色
- (急切求助)下面代码为什么在普通用户下不可以锁优盘(在线等)
- 请教界面上动态读取的文字与屏幕DPI有什么关系?
- 请教:mscvrt.dll报错,可能是什么原因呢?请各位赐教!
- 极怪的问题!现极度郁闷中!
- 弹出式菜单 小问题
- 请教,在VC里如何调用服务器上定义的对象?
- 如何实现一个程序,使得该程序能自动在其他dialog中的CEdit对象填入数据以及点击按钮
- 请教WINDOWS进程间通信的方法有几种?
- 大家都回家过年去了吗? DirectShow GetCurrentImage 怎么用?
- VC 执行SQL脚本问题
- VC 在文件右击菜单中 加入一个类似 "发送到"的项
在本地上生成一个 IP.TXT 文件,把自己的IP写进去现在遇到新问题: 不知道如何传到FTP上去 具体应该如何实现 用到什么相关函数? 是否有例程 提供 谢谢
虽然具体的我没做过
不过你可以去搜一下
CFtpConnection
try
{
//新建连接对象
m_pFtpConnection=m_pInetSession->GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword);
}
catch(CInternetException *pEx)
{
//获取错误
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
{m_log.AppendString(szError);
exit(1);
}
else
{
m_log.AppendString("There Was an exception");
pEx->Delete();
m_pFtpConnection=NULL;
exit(1);
}
} m_log.AppendString("连接ftp网址成功");
m_pRemoteFinder = new CFtpFileFind(m_pFtpConnection);之后用m_pFtpConnection->PutFile(本地文件,上传文件)完了
PutFile is a high-level routine that handles all of the operations associated with storing a file on an FTP server. Applications that only send data, or that require closer control over the file transfer, should use OpenFile and CInternetFile::Write.
Override the dwContext default to set the context identifier to a value of your choosing. The context identifier is associated with this specific operation of the CFtpConnection object created by its CInternetSession object. The value is returned to CInternetSession::OnStatusCallback to provide status on the operation with which it is identified. See the articleInternet First Steps: WinInet for more information about the context identifier.分享一下
CInternetSession * m_pInetSession; //会话对象
CFtpConnection * m_pFtpConnection; //连接对象
CFtpFileFind * m_pRemoteFinder; //远程查找文件对象
CFileFind m_LocalFinder; //本地查找文件对象
希望对你有帮助
说明 m_pInetSession 就是 CInternetSession类型的指针看返回值,定义
CInternetSession类
CInternetSession* m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
CFtpConnection* m_pFtpConnection;
try
{
//新建连接对象
m_pFtpConnection=m_pInetSession->GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword);
}
catch(CInternetException *pEx)
{
//获取错误
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
{//m_log.AppendString(szError);
MessageBox(szError);
exit(1);
}
else
{
MessageBox("There Was an exception");
pEx->Delete();
m_pFtpConnection=NULL;
exit(1);
}
}
MessageBox("连接ftp网址成功");
CFtpFileFind* m_pRemoteFinder = new CFtpFileFind(m_pFtpConnection);
if(!m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt"))
{
MessageBox("未发送成功");
}
经过调试发现:FTP连接是没有问题的 因为我先后使用了错误的域名 密码 用户名 爆出不同的错误提示 均正确 则 连接成功
但是接下来会提示 未发送成功 说明m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt")为空,也就是没有发送 求解惑 我该如何解决 谢谢
1,pEx生命
catch(CInternetException *pEx) 代码中已有2,m_log 还有 appstring函数声明
这个是我的写日志类,你直接注销掉就行了3,if(!m_pFtpConnection->PutFile("D://ip.txt","D://ip.txt"))
你这行有问题,看一下msdn就会明白,怎么能把D://ip.txt 上传到D://ip.txt这个呀,肯定是错误的
对函数GetFtpConnection(sFtpUrl,sFtpUser,sFtpPassword,21,true); 参数做了修改 后成功上传了 在此分享下 非常感谢大家的帮助 特别是lvxinjian_cn