最近用到freebsd10.2,然而倒騰圖形介面始終沒有成功,各種**無法拷貝到bsd上去,不可能用vi或者ee重複再敲一遍。
vmtools似乎也沒法安裝,於是就用ee敲了個最簡單的bsd上的服務端,接收檔案並儲存到本地。精簡版**如下:
#include #include #include #include #include struct filecopyinfo
;int main(int argc, char **argv)
while (s>0);
} return 0;
}
可以先在windows上編譯出完整版作為乙個客戶端來連線bsd上的精簡版,然後將完整版作為檔案傳輸到bsd,再在bsd上編譯出完整版,就可以實現雙向檔案拷貝了。
完整版可以在windows/linux/bsd上編譯,linux上需要指定-std=c++11 windows上最好是vs2013及以後版本,完整版如下:
#ifdef win32
#include #include #pragma comment(lib, "ws2_32.lib")
#else
#include #include #include #include // g++ this.cpp -std=c++11 -lpthread -o test
#endif
#include #include #include #include #include #include #include struct sockettool
template static int closesocket(socket_type skt)
static sockaddr_in geninaddr(const char *szip, unsigned uport)
static std::string printinaddr(const sockaddr_in& addr)
; inet_ntop(af_inet, (void*)&addr.sin_addr, buf, sizeof(buf));
auto port = ntohs(addr.sin_port);
std::stringstream ss;
ss << buf << ":" << port;
return ss.str();
} ~sockettool() };
struct filecopyinfo
;#ifdef win32
#include #else
#include #endif
void n2l(filecopyinfo& cpyinfo)
void l2n(filecopyinfo& cpyinfo)
template bool senddata(sockettype s, const char* buf, unsigned buflen)
else
}return true;
}bool sendfile(const char *plocalfile, const char *ip, int port)
sockettool sktinit;
auto s = socket(af_inet, sock_stream, 0);
auto addr = sockettool::geninaddr(ip, port);
auto ret = connect(s, (sockaddr*)&addr, sizeof(addr));
if (ret != 0)
filecopyinfo cpyinfo;
const char* psrcname = strrchr(plocalfile, '/');
if (psrcname == nullptr)
else
strcpy(cpyinfo.filename, psrcname);
ifs.seekg(0, std::ios::end);
auto filelen = ifs.tellg();
ifs.seekg(0, std::ios::beg);
std::cout << "sending " << filelen << " bytes...";
unsigned usended = 0;
cpyinfo.filelength = filelen;
l2n(cpyinfo);
if (senddata(s, (const char*)&cpyinfo, sizeof(cpyinfo)))
; do
else
} while (!ifs.eof());
} std::cout << usended << "/" << filelen << " bytes sended!" << std::endl;
sockettool::closesocket(s);
return usended == filelen;
}template bool recvdata(sockettype s, char* buf, unsigned buflen)
else
}return true;
}bool recvfile(const char *plocaldir, int port)
auto addr = sockettool::geninaddr("0.0.0.0", port);
if (bind(serv, (sockaddr*)&addr, sizeof(sockaddr)) == -1)
if (listen(serv, 5) == -1)
while (true)
else
filecopyinfo cpyinfo;
if (recvdata(con, (char*)&cpyinfo, sizeof(cpyinfo)))
;unsigned urest = cpyinfo.filelength;
while (urest > 0)
if (recvdata(con, buf, uread))
else
}std::cout << "recv finished: " << cpyinfo.filelength - urest << "/" << cpyinfo.filelength << std::endl;
}else
}} sockettool::closesocket(con);
} sockettool::closesocket(serv);
}int main(int argc, char **argv)
else if (argc == 3)
else
return 0;
}
TX1 跨平台檔案傳輸工具 使用記錄
最開始用過的跨平台工具為dukto,支援windows系統和x86架構ubuntu系統。但不支援arm架構ubuntu,tx1上就沒法使用。然後找到乙個替代軟體,iptux,在arm架構ubuntu上可以直接apt get安裝 sudo apt get install iptux該軟體可以在arm架...
網路檔案傳輸工具,秒殺各種網路檔案傳送工具的鐳速雲
如果有乙個支援儲存 共享 協作的平台,這些操作都將變得十分簡單。2010年,雲語科技專注於大資料傳輸加速及網路優化服務,致力於幫助各種機構在大資料時代實現更加高效的資料同步和資訊互動。鐳速雲是最具創新體驗的企業檔案協作雲平台。通過鐳速雲,您可以隨時隨地對檔案進行安全便捷的訪問 共享和協作,從而實現人...
VC檔案傳輸
vc 檔案傳輸的實現 2008 07 20 20 33 要實現檔案傳輸最簡單的辦法是寫兩個執行緒,乙個伺服器段的傳送處理執行緒,乙個客戶端的接收處理執行緒。執行緒處理函式需要宣告為類的靜態成員,由於不可訪問類內部的資料成員,所以引數傳遞裡面最好有個類的指標 伺服器段的傳送處理執行緒 cfiletra...