在下載作業中將遠端名稱改成新的網址。
語法
HRESULT SetRemoteName(
[in] LPCWSTR Val
);
參數
[in] Val
包含伺服器檔案名稱的空終止字串。 關於指定遠端名稱的資訊,請參閱 BG_FILE_INFO 結構中的 RemoteName 成員與備註區。
返回值
此方法回傳以下回傳值及其他值。
| 回傳碼 | Description |
|---|---|
|
成功 |
|
新的遠端名稱是無效的 URL,或是新網址過長(URL 不得超過 2,200 個字元)。 |
|
你無法呼叫此方法來處理上傳或上傳回覆的工作;這個方法只用於下載工作。 |
|
工作狀態無法 BG_JOB_STATE_CANCELLED 或 BG_JOB_STATE_ACKNOWLEDGED。 |
備註
通常,如果你想更改傳輸檔案的協定(例如從 SMB 到 HTTP),或是想更改檔案名稱或路徑,就會呼叫這個方法。
此方法回傳時不會序列化。 要序列化 變更,暫停 工作,呼叫此方法(若更換多個檔案,請迴圈),然後 繼續 工作。 呼叫 IBackgroundCopyJob::Resume 方法會序列化變更。
如果新遠端名稱的時間戳記或檔案大小與先前的遠端名稱不同,或新伺服器不支援檢查點恢復(針對 HTTP 遠端名稱),BITS 會重新啟動下載。 否則,傳輸會從新伺服器的同一位置繼續進行。 BITS 不會重新啟動已傳輸的檔案。
如果遠端名稱識別出伺服器訊息區塊(SMB)路徑,下表將標示在你恢復工作後可能發生的錯誤代碼。 這些錯誤會讓工作陷入 BG_JOB_STATE_ERROR 狀態。
| 錯誤碼 | Description |
|---|---|
HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) |
但找不到該名錄。 |
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) |
檔案未被找到。 |
HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) |
使用者無法存取 Val 指定的檔案。 |
範例
以下範例說明如何呼叫 SetRemoteName 方法來更改檔案的遠端名稱。 範例假設 IBackgroundCopyJob 變數 pJob 是有效的,且該工作包含一個或多個檔案。
IBackgroundCopyJob *pJob;
IEnumBackgroundCopyFiles* pFiles = NULL;
IBackgroundCopyFile* pFile = NULL;
IBackgroundCopyFile2* pFile2 = NULL;
WCHAR* pRemoteFileName = NULL;
ULONG cFileCount = 0;
hr = pJob->Suspend();
hr = pJob->EnumFiles(&pFiles);
if (SUCCEEDED(hr))
{
//Get the count of files in the job.
hr = pFiles->GetCount(&cFileCount);
//Enumerate the files in the job.
for (ULONG idx=0; idx<cFileCount; idx++)
{
hr = pFiles->Next(1, &pFile, NULL);
if (S_OK == hr)
{
//Get the local name of the file.
hr = pFile->GetRemoteName(&pRemoteFileName);
if (SUCCEEDED(hr))
{
//Determine if you want to replace the remote name of this file.
if (<CONDITIONGOESHERE>)
{
//Need to query the IBackgroundCopyFile interface for an IBackgroundCopyFile2
//interface pointer. The IBackgroundCopyFile2 interface contains the SetRemoteName method.
hr = pFile->QueryInterface(__uuidof(IBackgroundCopyFile2), (void**)&pFile2);
if (S_OK == hr)
{
hr = pFile2->SetRemoteName(L"<NEWURLGOESHERE>");
if (FAILED(hr))
{
//Handle error.
//Returns E_NOTIMPL if not a download job.
//Returns E_INVALIDARG if invalid URL.
}
}
else
{
//handle error. QueryInterface will return E_NOINTERFACE if the version of BITS
//running on the computer is less than BITS 2.0.
}
}
CoTaskMemFree(pRemoteFileName);
}
pFile->Release();
pFile = NULL;
}
else
{
//Handle error
break;
}
}
pFiles->Release();
pFiles = NULL;
}
hr = pJob->Resume(); //Force the job to serialize.
需求
| Requirement | 價值觀 |
|---|---|
| 最低支援的用戶端 | Windows Vista、Windows XP 搭配 Windows Server 2003 上的 SP2,KB842773,以及 Windows XP |
| 支援的最低伺服器 | Windows Server 2008、Windows Server 2003 與 SP1 |
| 目標平臺 | 窗戶 |
| Header | bits2_0.h(包含 Bits.h) |
| Library | Bits.lib |
| DLL | BitsPrx3.dll |