CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  控件

怎么解决用inet控件传送文本文件时,文本文件每行最后出现"^M"的问题(急)

楼主srljp()2004-12-03 14:47:34 在 VB / 控件 提问

最近我用inet控件编写了一个ftp文件上传程序,代码如下:  
              inet1.URL=ftp://username:password@169.196.1.1/ascii    
    inet1.Protocol=2-icFTP    
    inet1.Document=ascii  
    inet1.RemotePort=21    
    inet1.Username=username    
    inet1.   Password=password      
    Inet1.Execute   "ftp://username:password@169.196.1.1/ascii",   _    
              "PUT     D:\text.txt       text.txt"  
            在上传的服务服器上(SCO   UNIX系统)文本文件的每行最后多出”^M”,如何解决?我的E-mail:srljp@sina.com,本人在此谢谢了。  
  问题点数:0、回复次数:15Top

1 楼srljp()回复于 2004-12-03 22:55:28 得分 0

有那位高手请指点,本人十分感!!!Top

2 楼aohan(aohan)回复于 2004-12-03 22:59:55 得分 0

没试出来Top

3 楼srljp()回复于 2004-12-03 23:21:32 得分 0

怎样没试出来,我测试时客户端win   xp,服务服器端SCO   UNIX5.5。Top

4 楼creazyfish(梳分头的鱼)回复于 2004-12-05 23:00:07 得分 0

出现这种情况你只能先把文件转成binary的了.Top

5 楼srljp()回复于 2004-12-05 23:06:22 得分 0

creazyfish:我是一位新手,你能告知具体怎么转吗?非常感谢你!!!!!!Top

6 楼songyaowu(不以分多而蹭之;不因分少而不答; www.vb99.com)回复于 2004-12-06 15:35:12 得分 0

我记得好象是把ascii传输模式改为binary模式就可以的。若还不行就用下我写的这个转换工具进行转换吧!  
  http://www.skycn.com/soft/6394.htmlTop

7 楼srljp()回复于 2004-12-06 20:47:04 得分 0

Songyaowu(韧恒):谢谢你的转换工具,我试过后问题仍存在。如果在DOS下用ftp命令做,采用ascii模式上传则正常,而用binary模式上传就会出现用inet控件上传一样的结果,即被上传的文本中的每行尾有”^M”。是否是我对inet控件属性设置不正确造成?在我写的上传程序中Document属性未按ascii模式,而按binary模式传送?再次对你的关心表示深深的谢意!!!希望多指点。(本地端:win   xp,上传端:soc   unix   OpenServer5.05)Top

8 楼caimps(苦乐斋主人)回复于 2004-12-06 22:23:45 得分 0

在传输开始前使用bin命令可以将传输方式改为二进制  
  我记得在unix上从软盘读文件曾出过类似错误  
  当时是在dosread后面加了个   -a  
  Top

9 楼srljp()回复于 2004-12-06 22:34:13 得分 0

就是不能用binary传输方式,而要用ascii传输方式,这点我在DOS下用ftp命令试过。caimps:谢谢你的关心。Top

10 楼srljp()回复于 2004-12-06 22:39:43 得分 0

sco   unix下读dos软盘命令为:  
  #   dosdir   -aTop

11 楼caimps(苦乐斋主人)回复于 2004-12-06 22:50:08 得分 0

呵呵  
  我用的是AIX  
  dosdir只是列目录嘛  
  好就不用UNIX了  
  你查查man,应该会有与bin相对的命令,没准就是asc或ascii什么的Top

12 楼srljp()回复于 2004-12-06 22:55:47 得分 0

与bin相对的命令就是asc或ascii。但在用inet控件上传时就不行。  
  Top

13 楼creazyfish(梳分头的鱼)回复于 2004-12-06 23:22:17 得分 0

用ftp命令有直接的转换binary或者ascii的命令,但是很不幸,inet控件好象没有这个属性,这个其实也困扰了我很长时间,最后改成用API做的.而且这个好象本身和ftp服务器的设置有关系,因为我遇到过同样的ftp程序,对不用的ftp服务器,他会有binary或者ascii两种格式...Top

14 楼songyaowu(不以分多而蹭之;不因分少而不答; www.vb99.com)回复于 2004-12-07 08:57:03 得分 0

对不起啊楼主大人,我把你的问题看反了,我那个程序是将UNIX文件转DOS文本的,也就是把没有^M的文本加上^M,而对于DOS转UNIX我通常是在UNIX下做的,只需more   dosfile   >   unixfile,通过more命令输出的重定向到另一个文件来实现。  
  而对于你的问题我想有这样几个方案:  
   
  1.   如果文件不多,可以在UNIX下通过shell解决    
   
  2.   我发现在Inte控件中有一个DataTypeConstants枚举值,其中包括icByteArray和icString两个值,我对这个控件不熟悉,但我想应该有用的吧。按照你说的,可能是用ascii方式可以解决,我记不清了。  
   
  3.   如果Inte控件真的不能解决,恐怕你只能用API了来进行上传了。工作量也不算大,你可以参考下面的代码:  
  Const   FTP_TRANSFER_TYPE_UNKNOWN   =   &H0  
  Const   FTP_TRANSFER_TYPE_ASCII   =   &H1  
  Const   FTP_TRANSFER_TYPE_BINARY   =   &H2  
  Const   INTERNET_DEFAULT_FTP_PORT   =   21                               '   default   for   FTP   servers  
  Const   INTERNET_SERVICE_FTP   =   1  
  Const   INTERNET_FLAG_PASSIVE   =   &H8000000                         '   used   for   FTP   connections  
  Const   INTERNET_OPEN_TYPE_PRECONFIG   =   0                                         '   use   registry   configuration  
  Const   INTERNET_OPEN_TYPE_DIRECT   =   1                                                 '   direct   to   net  
  Const   INTERNET_OPEN_TYPE_PROXY   =   3                                                   '   via   named   proxy  
  Const   INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY   =   4       '   prevent   using   java/script/INS  
  Const   MAX_PATH   =   260  
  Private   Type   FILETIME  
          dwLowDateTime   As   Long  
          dwHighDateTime   As   Long  
  End   Type  
  Private   Type   WIN32_FIND_DATA  
          dwFileAttributes   As   Long  
          ftCreationTime   As   FILETIME  
          ftLastAccessTime   As   FILETIME  
          ftLastWriteTime   As   FILETIME  
          nFileSizeHigh   As   Long  
          nFileSizeLow   As   Long  
          dwReserved0   As   Long  
          dwReserved1   As   Long  
          cFileName   As   String   *   MAX_PATH  
          cAlternate   As   String   *   14  
  End   Type  
  Private   Declare   Function   InternetCloseHandle   Lib   "wininet"   (ByRef   hInet   As   Long)   As   Long  
  Private   Declare   Function   InternetConnect   Lib   "wininet.dll"   Alias   "InternetConnectA"   (ByVal   hInternetSession   As   Long,   ByVal   sServerName   As   String,   ByVal   nServerPort   As   Integer,   ByVal   sUserName   As   String,   ByVal   sPassword   As   String,   ByVal   lService   As   Long,   ByVal   lFlags   As   Long,   ByVal   lContext   As   Long)   As   Long  
  Private   Declare   Function   InternetOpen   Lib   "wininet.dll"   Alias   "InternetOpenA"   (ByVal   sAgent   As   String,   ByVal   lAccessType   As   Long,   ByVal   sProxyName   As   String,   ByVal   sProxyBypass   As   String,   ByVal   lFlags   As   Long)   As   Long  
  Private   Declare   Function   FtpSetCurrentDirectory   Lib   "wininet.dll"   Alias   "FtpSetCurrentDirectoryA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszDirectory   As   String)   As   Boolean  
  Private   Declare   Function   FtpGetCurrentDirectory   Lib   "wininet.dll"   Alias   "FtpGetCurrentDirectoryA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszCurrentDirectory   As   String,   lpdwCurrentDirectory   As   Long)   As   Long  
  Private   Declare   Function   FtpCreateDirectory   Lib   "wininet.dll"   Alias   "FtpCreateDirectoryA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszDirectory   As   String)   As   Boolean  
  Private   Declare   Function   FtpRemoveDirectory   Lib   "wininet.dll"   Alias   "FtpRemoveDirectoryA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszDirectory   As   String)   As   Boolean  
  Private   Declare   Function   FtpDeleteFile   Lib   "wininet.dll"   Alias   "FtpDeleteFileA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszFileName   As   String)   As   Boolean  
  Private   Declare   Function   FtpRenameFile   Lib   "wininet.dll"   Alias   "FtpRenameFileA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszExisting   As   String,   ByVal   lpszNew   As   String)   As   Boolean  
  Private   Declare   Function   FtpGetFile   Lib   "wininet.dll"   Alias   "FtpGetFileA"   (ByVal   hConnect   As   Long,   ByVal   lpszRemoteFile   As   String,   ByVal   lpszNewFile   As   String,   ByVal   fFailIfExists   As   Long,   ByVal   dwFlagsAndAttributes   As   Long,   ByVal   dwFlags   As   Long,   ByRef   dwContext   As   Long)   As   Boolean  
  Private   Declare   Function   FtpPutFile   Lib   "wininet.dll"   Alias   "FtpPutFileA"   (ByVal   hConnect   As   Long,   ByVal   lpszLocalFile   As   String,   ByVal   lpszNewRemoteFile   As   String,   ByVal   dwFlags   As   Long,   ByVal   dwContext   As   Long)   As   Boolean  
  Private   Declare   Function   InternetGetLastResponseInfo   Lib   "wininet.dll"   Alias   "InternetGetLastResponseInfoA"   (lpdwError   As   Long,   ByVal   lpszBuffer   As   String,   lpdwBufferLength   As   Long)   As   Boolean  
  Private   Declare   Function   FtpFindFirstFile   Lib   "wininet.dll"   Alias   "FtpFindFirstFileA"   (ByVal   hFtpSession   As   Long,   ByVal   lpszSearchFile   As   String,   lpFindFileData   As   WIN32_FIND_DATA,   ByVal   dwFlags   As   Long,   ByVal   dwContent   As   Long)   As   Long  
  Private   Declare   Function   InternetFindNextFile   Lib   "wininet.dll"   Alias   "InternetFindNextFileA"   (ByVal   hFind   As   Long,   lpvFindData   As   WIN32_FIND_DATA)   As   Long  
  Const   PassiveConnection   As   Boolean   =   True  
  Private   Sub   Form_Load()  
          Dim   hConnection   As   Long,   hOpen   As   Long,   sOrgPath     As   String  
          'open   an   internet   connection  
          hOpen   =   InternetOpen("API-Guide   sample   program",   INTERNET_OPEN_TYPE_PRECONFIG,   vbNullString,   vbNullString,   0)  
          'connect   to   the   FTP   server  
          hConnection   =   InternetConnect(hOpen,   "your   ftp   server",   INTERNET_DEFAULT_FTP_PORT,   "your   login",   "your   password",   INTERNET_SERVICE_FTP,   IIf(PassiveConnection,   INTERNET_FLAG_PASSIVE,   0),   0)  
          'create   a   buffer   to   store   the   original   directory  
          sOrgPath   =   String(MAX_PATH,   0)  
          'get   the   directory  
          FtpGetCurrentDirectory   hConnection,   sOrgPath,   Len(sOrgPath)  
          'create   a   new   directory   'testing'  
          FtpCreateDirectory   hConnection,   "testing"  
          'set   the   current   directory   to   'root/testing'  
          FtpSetCurrentDirectory   hConnection,   "testing"  
          'upload   the   file   'test.htm'  
          FtpPutFile   hConnection,   "C:\test.htm",   "test.htm",   FTP_TRANSFER_TYPE_UNKNOWN,   0  
          'rename   'test.htm'   to   'apiguide.htm'  
          FtpRenameFile   hConnection,   "test.htm",   "apiguide.htm"  
          'enumerate   the   file   list   from   the   current   directory   ('root/testing')  
          EnumFiles   hConnection  
          'retrieve   the   file   from   the   FTP   server  
          FtpGetFile   hConnection,   "apiguide.htm",   "c:\apiguide.htm",   False,   0,   FTP_TRANSFER_TYPE_UNKNOWN,   0  
          'delete   the   file   from   the   FTP   server  
          FtpDeleteFile   hConnection,   "apiguide.htm"  
          'set   the   current   directory   back   to   the   root  
          FtpSetCurrentDirectory   hConnection,   sOrgPath  
          'remove   the   direcrtory   'testing'  
          FtpRemoveDirectory   hConnection,   "testing"  
          'close   the   FTP   connection  
          InternetCloseHandle   hConnection  
          'close   the   internet   connection  
          InternetCloseHandle   hOpen  
  End   Sub  
  Public   Sub   EnumFiles(hConnection   As   Long)  
          Dim   pData   As   WIN32_FIND_DATA,   hFind   As   Long,   lRet   As   Long  
          'set   the   graphics   mode   to   persistent  
          Me.AutoRedraw   =   True  
          'create   a   buffer  
          pData.cFileName   =   String(MAX_PATH,   0)  
          'find   the   first   file  
          hFind   =   FtpFindFirstFile(hConnection,   "*.*",   pData,   0,   0)  
          'if   there's   no   file,   then   exit   sub  
          If   hFind   =   0   Then   Exit   Sub  
          'show   the   filename  
          Me.Print   Left(pData.cFileName,   InStr(1,   pData.cFileName,   String(1,   0),   vbBinaryCompare)   -   1)  
          Do  
                  'create   a   buffer  
                  pData.cFileName   =   String(MAX_PATH,   0)  
                  'find   the   next   file  
                  lRet   =   InternetFindNextFile(hFind,   pData)  
                  'if   there's   no   next   file,   exit   do  
                  If   lRet   =   0   Then   Exit   Do  
                  'show   the   filename  
                  Me.Print   Left(pData.cFileName,   InStr(1,   pData.cFileName,   String(1,   0),   vbBinaryCompare)   -   1)  
          Loop  
          'close   the   search   handle  
          InternetCloseHandle   hFind  
  End   Sub  
  Sub   ShowError()  
          Dim   lErr   As   Long,   sErr   As   String,   lenBuf   As   Long  
          'get   the   required   buffer   size  
          InternetGetLastResponseInfo   lErr,   sErr,   lenBuf  
          'create   a   buffer  
          sErr   =   String(lenBuf,   0)  
          'retrieve   the   last   respons   info  
          InternetGetLastResponseInfo   lErr,   sErr,   lenBuf  
          'show   the   last   response   info  
          MsgBox   "Error   "   +   CStr(lErr)   +   ":   "   +   sErr,   vbOKOnly   +   vbCritical  
  End   Sub  
   
  4.   在使用Inte控件上传前,   就将其转为unix文本,这很简单,只要以二进制方式打开文件,将行尾的^M去掉就可以了,因为unix文本只有换行没有回车的。然后再以二进行方式上传。  
   
  希望我的想法对你能有帮助。Top

15 楼srljp()回复于 2004-12-20 21:20:14 得分 0

此问题我已通过批处题解决了,谢谢大家的回答,特别感谢songyaowu(韧恒)、creazyfish(梳分头的鱼)、caimps(苦乐斋主人)。Top

相关问题

  • 用inet控件下载文本文件的问题
  • EDIT控件中显示文本文件的问题!
  • 怎样用Winsock控件接受长度>65535的文本文件???
  • 怎样读取一个300多M的文本文件??急
  • 菜鸟问题:用Memo控件怎样连接文本文件,并且可以通过Memo控件对文本文件增删修?
  • 怎样将一个文本文件中的内容显示在一个text控件中?在此控件中进行编辑后再保存进文本文件?
  • vsflexgrid控件绑定一个文本文件(.txt)文件时,如何将控件上的修改的内容写到这个文本文件中?
  • 如何用memo控件实现对文本文件的分页显示?
  • 如何在文本框控件中显示文本文件的内容
  • 如何将一个文本文件内容读取到DataGrid控件里?

关键词

  • win32
  • 控件
  • unix
  • 解决
  • 文件
  • 模式
  • 转换
  • 属性
  • sco
  • 文本

得分解答快速导航

  • 帖主:srljp

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo